﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YJKRevitBase.WinForm;

namespace YArchitech.Public.ExcelToView
{
	public partial class SelectDataForm : EscBaseForm
	{
		public SelectDataForm(ExternalCommandData commandData, WindowHandle _hWndRevit)
		{
			this.m_hWndRevit = _hWndRevit;
			this.m_CommandData = commandData;
			this.InitializeComponent();
		}

		internal List<bool> Lstblresult
		{
			get
			{
				return this.blresult;
			}
			set
			{
				this.blresult = value;
			}
		}

		internal List<List<string>> LstexcelData
		{
			get
			{
				return this.excelData;
			}
		}

		private void button1_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Title = "导入表格";
			openFileDialog.Filter = "EXCEL文件(*.xls,*.xlsx)|*.xls;*.xlsx";
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				string fileName = openFileDialog.FileName;
				this.textBox1.Text = fileName;
			}
		}

		private void button2_Click_1(object sender, EventArgs e)
		{
			this.NeedData.ShowDialog();
		}

		private void button4_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void button3_Click(object sender, EventArgs e)
		{
			base.Hide();
			List<int> lstUseData = this.NeedData.LstUseData;
			string wantSheetName = "Sheet1";
			if (this.textBox1.Text == "")
			{
				YJKMessageBox.Show("请先选择文件路径！");
				return;
			}
			this.excelData = this.thisLoader.GetExcelValue(lstUseData, -1, wantSheetName, this.textBox1.Text);
			if (this.excelData == null)
			{
				base.Close();
				return;
			}
			PreviewData previewData = new PreviewData(this.excelData, this.m_CommandData);
			if (previewData.ShowDialog(this.m_hWndRevit) == DialogResult.OK)
			{
				base.Close();
				this.Lstblresult = previewData.Lstblresult;
				this.lstElemId = previewData.listViewSheets;
			}
		}

		private void SelectDataForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private WindowHandle m_hWndRevit;

		private SetNeedData NeedData = new SetNeedData();

		private ExternalCommandData m_CommandData;

		private ExcelLoaderBase thisLoader = ExcelLoader_LateBound.GetExcelLoader();

		private List<List<string>> excelData;

		private List<bool> blresult = new List<bool>();

		public List<ViewSheet> lstElemId = new List<ViewSheet>();
	}
}
